<?php

namespace app\teacher\controller\learn;

use app\common\controller\Frontend;
use app\common\model\banxi\learn\LearnVocabularyRecord as LearnVocabularyRecordModel;
use app\common\service\UploadService;
use app\common\service\learn\LearnVocabularyService;
use think\facade\Log;

/*
 * 词汇量测试
 * */
class LearnVocabularyRecord extends Frontend
{
    protected array $noNeedLogin = [''];

    protected array $noNeedPermission = ['*'];

    public function initialize(): void
    {
        parent::initialize();
    }

    /*
     * 分页-测评记录
     * */
    public function listMyVocabularyPage()
    {
        $limit = $this->request->get('limit', 20);
        $index = $this->request->get('index', 1);

        $user = $this->auth->getUserInfo();
        $LearnVocabularyRecordModel = new LearnVocabularyRecordModel();

        $where = [];
        $where[] = ['accountId', '=', $user['id']];
        $where[] = ['isSubmit', '=', 1];
        $where[] = ['accountType', '=', 4];//测试人类型 1=平台 2=机构 3=学员 4=教练
        $list = $LearnVocabularyRecordModel
            ->with(['settingInfo'])
            ->where($where)
            ->order('id', 'desc')
            ->paginate([
                'page' => $index,
                'list_rows' => $limit,
            ]);

        $this->ok('操作成功', result_row($list));
    }

    /*
     * 查询-测评评估报告
     * */
    public function getDetail()
    {
        $id = $this->request->get('id', 0);

        $LearnVocabularyRecordModel = new LearnVocabularyRecordModel();
        $info = $LearnVocabularyRecordModel->getDetail($id);

        $this->ok('操作成功', $info);
    }

    /*
     * 开始-测试词汇量
     * */
    public function startVocabulary()
    {
        $skRecordId = $this->request->post('skRecordId', null);
        $studentId = $this->request->post('studentId', null);

        $user = $this->auth->getUserInfo();
        $accountId = $user['id'];
        $accountType = 4;
        $tutorTrainerId = null;
        if ($skRecordId){
            if(!$studentId){
                $this->fail('学生ID不可为空');
            }
            $accountType = 3;
            $tutorTrainerId = $accountId;
        }

        $LearnVocabularyService = new LearnVocabularyService();
        $info = $LearnVocabularyService->startVocabulary($accountId, $accountType, $skRecordId, $tutorTrainerId);

        $this->ok('操作成功', $info);
    }

    /*
     * 提交-词汇量测试
     * */
    public function submitVocabulary()
    {
        $submit = $this->request->post();

        $user = $this->auth->getUserInfo();
        $LearnVocabularyService = new LearnVocabularyService();
        $info = $LearnVocabularyService->submitVocabulary(null,$user['id'],$submit);

        $this->ok('操作成功', $info);
    }

}